<!--
/*******************************************************************************
#      ____               __          __  _      _____ _       _               #
#     / __ \              \ \        / / | |    / ____| |     | |              #
#    | |  | |_ __   ___ _ __ \  /\  / /__| |__ | |  __| | ___ | |__   ___      #
#    | |  | | '_ \ / _ \ '_ \ \/  \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \     #
#    | |__| | |_) |  __/ | | \  /\  /  __/ |_) | |__| | | (_) | |_) |  __/     #
#     \____/| .__/ \___|_| |_|\/  \/ \___|_.__/ \_____|_|\___/|_.__/ \___|     #
#           | |                                                                #
#           |_|                 _____ _____  _  __                             #
#                              / ____|  __ \| |/ /                             #
#                             | (___ | |  | | ' /                              #
#                              \___ \| |  | |  <                               #
#                              ____) | |__| | . \                              #
#                             |_____/|_____/|_|\_\                             #
#                                                                              #
#                              (c) 2010-2011 by                                #
#           University of Applied Sciences Northwestern Switzerland            #
#                     Institute of Geomatics Engineering                       #
#                           martin.christen@fhnw.ch                            #
********************************************************************************
*     Licensed under MIT License. Read the file LICENSE for more information   *
*******************************************************************************/

                      Tutorial 10: Putting Image on Terrain
                      
*******************************************************************************/
-->
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="../../../external/closure-library/closure/goog/base.js"></script>
<script type="text/javascript" src="../../../compiled/deps.js"></script>
<script type="text/javascript">goog.require('owg.OpenWebGlobe');</script>

<script type="text/javascript">

var aoeimage = null;
var aoeimagelayer = null;

//------------------------------------------------------------------------------
// Render-Event: called every frame:
function OnRender(context)
{  
   
   ogSetTextColor(context, 0,1,0);
   ogDrawText(context, "Press 1 to add, 2 to remove", 0, 20);
}
//------------------------------------------------------------------------------
// Mouse-Down-Event: Called when a mouse button is pressed
function OnMouseDown(context, button, mx, my)
{
   return;
 
}

//------------------------------------------------------------------------------

function OnKeyDown(ctx,key)
{
   if(key == 49) // 1 - Create a geometry Layer and load a model
   {
      //img = new aoeImage(ctx);
      options = 
      {
      longitude0 :108.799532930521,
      latitude0  :40.6338723204708,
      longitude1 :108.914426930521,
      latitude1  :40.6442853204708,
      url        : "texture.png"
      };
      aoeimage = ogCreateAoeImage(aoeimagelayer, options);
      ogFlyTo(ogGetScene(ctx),108.799532930521,40.6338723204708, 18000, 0, -90 ,0);
     
   }

   if(key == 50) // 2 - Create a second model out of a json object and add it to the layer
   {
      ogDestroyAoeImage(aoeimage);
   }

}

//------------------------------------------------------------------------------
function main()
{
   // (0) Set location of Artwork directory. Because of CORS this can't be local
   // if you want to open this using file://...
   ogSetArtworkDirectory("http://www.openwebglobe.org/art/");
   
   // (1) create an OpenWebGlobe context using canvas
   // first parameter is canvas-id and second is "fullscreen"
   
   var ctx = ogCreateContextFromCanvas("canvas", true);
   
   // (2) Create a virtual globe
   var globe = ogCreateGlobe(ctx);
   
   // (3) Add an image and an elevation layer

   var imgGoogleMap = 
   {
      url     : ["http://khm0.google.com", "http://khm1.google.com"],
      service : "goo"
   };
    var imgOpenStreetMap = 
   {
      url     : ["http://a.tile.openstreetmap.org", "http://b.tile.openstreetmap.org", "http://c.tile.openstreetmap.org" ],
      service : "osm"
   };
   //ogAddImageLayer(globe, imgOpenStreetMap);
   ogAddImageLayer(globe, imgGoogleMap);
   
         
   //ogAddImageLayer(globe, imgBlueMarble500);
   //ogAddImageLayer(globe, imgLandsat_CH);
   //ogAddElevationLayer(globe, elvSRTM_CH);
   
   // (4) Set the "Render-Callback" function.
   // The callback function will be called everytime a frame is drawn.
   ogSetRenderFunction(ctx, OnRender);
   
   // (5) Set the mouse down function. 
   ogSetMouseDownFunction(ctx, OnMouseDown);
   
   // (6) Set the background color
   ogSetBackgroundColor(ctx, 0.2,0.2,0.7,1);
   
   ogSetKeyDownFunction(ctx, OnKeyDown);
   var scene = ogGetScene(ctx);
   var world = ogGetWorld(scene);   
   aoeimagelayer = ogCreateAoeImageLayer(world,"aoeimages");

   

}
//------------------------------------------------------------------------------
   
</script>

</head>
<body onload="main()" style="padding:0px; margin:0px; overflow:hidden;">
   <div style="text-align: center">
   <canvas id="canvas"></canvas>          
   </div>
</body>
</html>
